<?php
namespace Home\Controller;
use Think\Controller;
class ContactController extends Controller {

	/**
	 * 初始化
	 */
	public function __construct() {
		parent::__construct();
	}
	
	/**
	 * 通许录
	 */
	public function index() {
		$key  = I('get.searchkey','','strip_tags');
		$nickname = I('get.nickname','','strip_tags');
		if(!empty($nickname)) {
			$wheren['nickname'] = array('like','%'.$key.'%');
		}
		$address = I('get.address','','strip_tags');
		if(!empty($address)) {
			$wheren['address'] = array('like','%'.$key.'%');
		}
		$mobile = I('get.mobile','','strip_tags');
		if(!empty($mobile)) {
			$wheren['mobile'] = array('like','%'.$key.'%');
		}
		$qq = I('get.qq','','strip_tags');
		if(!empty($qq)) {
			$wheren['qq'] = array('like','%'.$key.'%');
		}
		$cs = I('get.cs','','strip_tags');
		if(!empty($cs)) {
			$wheren['cs'] = array('like','%'.$key.'%');
		}
		$qg = I('get.qg','','strip_tags');
		if(!empty($qg)) {
			$wheren['qg'] = array('like','%'.$key.'%');
		}
		$company = I('get.company','','strip_tags');
		if(!empty($company)) {
			$wheren['company'] = array('like','%'.$key.'%');
		}

		$province = I('get.province','','strip_tags');
		if(!empty($province)) {
			$wheren['province'] = array('like','%'.$key.'%');
		} else {
			unset($_SESSION['province']);
		}

		$city = I('get.city','','strip_tags');
		if(!empty($city)) {
			$wheren['city'] = array('like','%'.$key.'%');
		}

		if(empty($nickname) && empty($address) && empty($mobile) && empty($qq) && empty($cs) && empty($qg) && empty($company) && empty($province) && empty($city)) {
			$wheren['nickname'] = array('like','%'.$key.'%');
		} else {
			$wheren['_logic'] = 'or';
		}

		$getprovince = I('get.province','','strip_tags');
		if(!empty($getprovince)) {
			if($getprovince == '全部') {
				//$_SESSION['province'] = '';
				unset($_SESSION['province']);
			} else {
				$_SESSION['province'] = $getprovince;
			}
		}
		$where['_complex'] = $wheren;
		if(!empty($_SESSION['province'])) {
			$where['province'] = $_SESSION['province'];
		}

		$list = D('Admin/address')->hselect($where);
		$this->assign('list',$list);
		$this->assign('listzm',$listzm);

		$this->display();
	}
	
	/**
	 * 通讯录详情
	 */
	public function info() {
		$id = I('get.id','','intval');
		$info = D('address')->find($id);

		if(!empty($info['mobile'])) {
			$mobilearr = json_decode($info['mobile'],true);
			$info['mobilearr'] = $mobilearr;
			$this->assign('mobilearr',$mobilearr);
		}

		if(!empty($info['photo'])) {
			$info['photos'] = explode('|',$info['photo']);
		}
		$this->assign('photoarr',$info['photos']);

		$this->assign('info',$info);
		$this->display();
	}

}
